package com.cms.web.dict;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;

import com.cms.persistence.customerInfo.KHDAZD;
import com.cms.persistence.customerInfo.KHFJXX;
import com.cms.persistence.customerInfo.KHLXZD;
import com.cms.persistence.customerInfo.KHSSZD;
import com.cms.persistence.customerInfo.KHSXZD;
import com.cms.persistence.customerInfo.QYXZZD;
import com.dms.pub.util.UploadFileUtil;
import com.pub.util.FileUtil;
import com.web.BaseController;
import com.efounder.dict.DMTServiceMgr;
import com.efounder.dict.FCTServiceMgr;
import com.efounder.eai.data.JResponseObject;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.builder.util.EMPRowSetUtil;

import dwz.dal.common.sequence.UUIDGenerator;

@Controller
@RequestMapping(value="/cmsCustomerInfo")
public class CustomerInfoController extends BaseController{
	@Autowired
	private                            DMTServiceMgr                   DMTService;

	@Autowired
	private                            FCTServiceMgr                   FCTService;
	
	@Autowired
	public                               HttpSession                      session;

	/**
	 * 客户属性列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttributes")
	public String customerAttributesList(Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("KHSXZD", "F_SXBH", "", null, 0, 100);
		model.addAttribute("dataset", dataset);
		return "/cms/dict/khsx/list";
	}
	
	/**
	 * 客户属性列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttributes/list")
	public String customerAttributesList(@RequestParam String keywords, Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("KHSXZD", "F_SXMC", keywords, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("keywords", keywords);
		return "/cms/dict/khsx/list";
	}
	
	/**
	 * 客户属性添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttributes/add")
	public String customerAttributesAdd(Model model) {	
		String tempBh = DMTService.getTempDictBM("KHSXZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_SXBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khsx/add";
	}
	
	/**
	 * 客户属性添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/customerAttributes/insert", method = RequestMethod.POST)
	public ModelAndView customerAttributesInsert(KHSXZD sxzd) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(sxzd);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTService.insertDCTRow("KHSXZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 客户属性编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttributes/edit/{F_SXBH}")
	public String customerAttributesEdit(@PathVariable("F_SXBH") String F_SXBH, Model model) {
		EFRowSet rowset = DMTService.getRow("KHSXZD", F_SXBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khsx/edit";
	}
	
	/**
	 * 客户属性编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttributes/update")
	public ModelAndView customerAttributesUpdate(KHSXZD sxzd, Model model) {
		EFRowSet rowset = DMTService.getRow("KHSXZD", sxzd.getF_SXBH());
		rowset.putString("F_SXMC", sxzd.getF_SXMC());
		rowset.putString("F_SYZT", sxzd.getF_SYZT());
		JResponseObject RO = DMTService.updateRow("KHSXZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 客户属性删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttributes/delete/{F_ZDBH}")
	public ModelAndView customerAttributesDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTService.deleteRow("KHSXZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * 客户属性列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerType")
	public String customerTypeList(Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("KHLXZD", "F_LXBH", "", null, 0, 100);
		model.addAttribute("dataset", dataset);
		return "/cms/dict/khlx/list";
	}
	
	/**
	 * 客户属性列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerType/list")
	public String customerTypeList(@RequestParam String keywords, Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("KHLXZD", "F_LXMC", keywords, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("keywords", keywords);
		return "/cms/dict/khlx/list";
	}
	
	/**
	 * 客户属性添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerType/add")
	public String customerTypeAdd(Model model) {	
		String tempBh = DMTService.getTempDictBM("KHLXZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_LXBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khlx/add";
	}
	
	/**
	 * 客户属性添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/customerType/insert", method = RequestMethod.POST)
	public ModelAndView customerTypeInsert(KHLXZD lxzd) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(lxzd);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTService.insertDCTRow("KHLXZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 客户属性编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerType/edit/{F_ZDBH}")
	public String customerTypeEdit(@PathVariable("F_ZDBH") String F_ZDBH, Model model) {
		EFRowSet rowset = DMTService.getRow("KHLXZD", F_ZDBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khlx/edit";
	}
	
	/**
	 * 客户属性编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerType/update")
	public ModelAndView customerTypeUpdate(KHLXZD sxzd, Model model) {
		EFRowSet rowset = DMTService.getRow("KHLXZD", sxzd.getF_LXBH());
		rowset.putString("F_LXMC", sxzd.getF_LXMC());
		rowset.putString("F_SYZT", sxzd.getF_SYZT());
		JResponseObject RO = DMTService.updateRow("KHLXZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 客户属性删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerType/delete/{F_ZDBH}")
	public ModelAndView customerTypeDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTService.deleteRow("KHLXZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	/**
	 * 企业性质列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProvinces")
	public String customerProvincesList(Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("KHSSZD", "F_SSBH", "", null, 0, 100);
		model.addAttribute("dataset", dataset);
		return "/cms/dict/khss/list";
	}
	
	/**
	 * 企业性质列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProvinces/list")
	public String customerProvincesList(@RequestParam String keywords, Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("KHSSZD", "F_SSMC", keywords, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("keywords", keywords);
		return "/cms/dict/khss/list";
	}
	
	/**
	 * 客户省市添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProvinces/add")
	public String customerProvincesAdd(Model model) {	
		String tempBh = DMTService.getTempDictBM("KHSSZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_SSBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khss/add";
	}
	
	/**
	 * 客户省市添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/customerProvinces/insert", method = RequestMethod.POST)
	public ModelAndView customerProvincesInsert(KHSSZD sszd) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(sszd);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTService.insertDCTRow("KHSSZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 客户省市编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProvinces/edit/{F_ZDBH}")
	public String customerProvincesEdit(@PathVariable("F_ZDBH") String F_ZDBH, Model model) {
		EFRowSet rowset = DMTService.getRow("KHSSZD", F_ZDBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khss/edit";
	}
	
	/**
	 * 客户省市编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProvinces/update")
	public ModelAndView customerProvincesUpdate(KHSSZD sszd, Model model) {
		EFRowSet rowset = DMTService.getRow("KHSSZD", sszd.getF_SSBH());
		rowset.putString("F_SSMC", sszd.getF_SSMC());
		rowset.putString("F_SYZT", sszd.getF_SYZT());
		JResponseObject RO = DMTService.updateRow("KHSSZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 客户省市删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProvinces/delete/{F_ZDBH}")
	public ModelAndView customerProvincesDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTService.deleteRow("KHSSZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	/**
	 * 企业性质列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/enterpriseNature")
	public String enterpriseNatureList(Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("QYXZZD", "F_XZBH", "", null, 0, 100);
		model.addAttribute("dataset", dataset);
		return "/cms/dict/qyxz/list";
	}
	
	/**
	 * 企业性质列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/enterpriseNature/list")
	public String enterpriseNatureList(@RequestParam String keywords, Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("QYXZZD", "F_XZMC", keywords, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("keywords", keywords);
		return "/cms/dict/qyxz/list";
	}
	
	/**
	 * 企业性质添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/enterpriseNature/add")
	public String enterpriseNatureAdd(Model model) {	
		String tempBh = DMTService.getTempDictBM("QYXZZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_XZBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/qyxz/add";
	}
	
	/**
	 * 企业性质添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/enterpriseNature/insert", method = RequestMethod.POST)
	public ModelAndView enterpriseNatureInsert(QYXZZD qyxz) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(qyxz);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTService.insertDCTRow("QYXZZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 企业性质编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/enterpriseNature/edit/{F_ZDBH}")
	public String enterpriseNatureEdit(@PathVariable("F_ZDBH") String F_ZDBH, Model model) {
		EFRowSet rowset = DMTService.getRow("QYXZZD", F_ZDBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/qyxz/edit";
	}
	
	/**
	 * 企业性质编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/enterpriseNature/update")
	public ModelAndView enterpriseNatureUpdate(QYXZZD qyxz, Model model) {
		EFRowSet rowset = DMTService.getRow("QYXZZD", qyxz.getF_XZBH());
		rowset.putString("F_XZMC", qyxz.getF_XZMC());
		rowset.putString("F_SYZT", qyxz.getF_SYZT());
		JResponseObject RO = DMTService.updateRow("QYXZZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 企业性质删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/enterpriseNature/delete/{F_ZDBH}")
	public ModelAndView enterpriseNatureDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTService.deleteRow("QYXZZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

	/**
	 * 客户档案列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProfiles")
	public String customerProfilesList(Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("KHDAZD", "F_KHBH", "", null, 0, 100);
		model.addAttribute("dataset", dataset);
		return "/cms/dict/khda/list";
	}
	
	/**
	 * 客户档案列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProfiles/list")
	public String customerProfilesList(@RequestParam String keywords, Model model) {	
		EFDataSet dataset = DMTService.searchDictRow("KHDAZD", "F_KHMC", keywords, null, 0, 100);
		model.addAttribute("dataset", dataset);
		model.addAttribute("keywords", keywords);
		return "/cms/dict/khda/list";
	}
	
	/**
	 * 客户档案添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProfiles/add")
	public String customerProfilesAdd(Model model) {	
		String   tempBh = DMTService.getTempDictBM("KHDAZD");
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_KHBH", tempBh);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khda/add";
	}
	
	/**
	 * 客户档案添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/customerProfiles/insert", method = RequestMethod.POST)
	public ModelAndView customerProfilesInsert(KHDAZD khda) {	
		EFRowSet rowset;
		try {
			rowset = EMPRowSetUtil.createRowSet(khda);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		JResponseObject RO = DMTService.insertDCTRow("KHDAZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 客户档案编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProfiles/edit/{F_ZDBH}")
	public String customerProfilesEdit(@PathVariable("F_ZDBH") String F_ZDBH, Model model) {
		EFRowSet     rowset = DMTService.getRow("KHDAZD", F_ZDBH);
		EFDataSet fjDataSet = DMTService.searchDictRow("KHFJXX", "F_KHBH", F_ZDBH, null, 0, 100);
		model.addAttribute("dictObject", rowset);
		model.addAttribute("fjDataSet", fjDataSet);
		return "/cms/dict/khda/edit";
	}
	
	/**
	 * 客户档案编辑保存
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProfiles/update")
	public ModelAndView customerProfilesUpdate(KHDAZD khda, Model model) {
		EFRowSet rowset = DMTService.getRow("KHDAZD", khda.getF_KHBH());
		try {
			rowset = EMPRowSetUtil.createRowSet(khda);
		} catch (Exception e) {
			e.printStackTrace();
			return ajaxDoneError(e.getMessage());
		}
		rowset.putString("F_KHBH", khda.getF_KHBH());
		JResponseObject RO = DMTService.updateRow("KHDAZD", rowset);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	/**
	 * 客户档案删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerProfiles/delete/{F_ZDBH}")
	public ModelAndView customerProfilesDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTService.deleteRow("KHDAZD", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/**
	 * 客户附件列表
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttachment/list")
	public String customerAttachmentList(@RequestParam String F_KHBH, Model model) {
		EFRowSet   rowset = DMTService.getRow("KHDAZD", F_KHBH);
		EFDataSet dataSet = DMTService.searchDictRow("KHFJXX", "F_KHBH", F_KHBH, null, 0, 100);
		model.addAttribute("dictObject", rowset);
		model.addAttribute("fjDataSet", dataSet);
		return "/cms/dict/khda/dafj/list";
	}
	
	/**
	 * 客户附件添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttachment/add")
	public String customerAttachmentAdd(@RequestParam String F_KHBH, Model model) {	
		EFRowSet rowset = EFRowSet.getInstance();
		rowset.putString("F_KHBH", F_KHBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khda/dafj/add";
	}
	
	/**
	 * 客户附件添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/customerAttachment/insert", method = RequestMethod.POST)
	public String customerAttachmentInsert(KHFJXX fjxx, @RequestParam String F_KHBH, HttpServletRequest request, HttpServletResponse response) {	
		String                                   fileName;
		String                                newFileName = null;
		String                              fileSeparator = System.getProperty("file.separator");
		MultipartHttpServletRequest      multipartRequest = (MultipartHttpServletRequest) request;    
		String                                servletPath = request.getRealPath("") + fileSeparator + "upload" + fileSeparator + "cms";
		String                                  strFolder = fjxx.getF_KHBH();
		String                                 forwardUrl = request.getParameter("forwardUrl");
		Map<String, MultipartFile>                fileMap = multipartRequest.getFileMap();  		

		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {    
             // 上传文件名    
             System.out.println("key: " + entity.getKey());    
             MultipartFile mf = entity.getValue();    
             fileName = mf.getOriginalFilename();           
             String uuid = UUIDGenerator.nextId();// 返回一个随机UUID。
             
             newFileName = servletPath + fileSeparator + strFolder + fileSeparator  + uuid;// 构成新文件名。
             
             //判断目录是否存在，每天上传的申请单都放到对应的一个目录下
             FileUtil.createDirectory(servletPath + fileSeparator + strFolder);
             File uploadFile = new File(newFileName);    
             try {  
            	 FileCopyUtils.copy(mf.getBytes(), uploadFile); 
                 EFRowSet rowset;
                 rowset = EMPRowSetUtil.createRowSet(fjxx);
                 rowset.putString("F_FJBH", uuid);
                 rowset.putString("F_FJMC", fileName);
         		 JResponseObject RO = FCTService.insertFCTRow("KHFJXX", rowset);
         		 response.getWriter().write(newFileName);
         		 response.setContentType("text/html"); 
         		 response.setCharacterEncoding("utf-8"); 
         		 PrintWriter out = response.getWriter(); 
         		 
         		forwardUrl += "?F_KHBH=" + fjxx.getF_KHBH();
         		 if(RO.getErrorCode() == -1) {
         			out.write("<script>parent.callbackKHDAFJSubmit('false','"+RO.getErrorString()+"','')</script>");  
        		} else {
        			out.write("<script>parent.callbackKHDAFJSubmit('true','"+RO.ResponseObject.toString()+"','" + forwardUrl + "')</script>");  
        		}
	         } catch (Exception e) {  
	             e.printStackTrace();  
	         }    
		}   
        return null; 
	}
	
	/**
	 * 客户档案删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttachment/edit/{F_ZDBH}")
	public String customerAttachmentEdit(@PathVariable("F_ZDBH") String F_ZDBH, Model model) {	
		EFRowSet rowset = DMTService.getRow("KHFJXX", "F_FJBH", F_ZDBH);
		model.addAttribute("dictObject", rowset);
		return "/cms/dict/khda/dafj/edit";
	}
	
	/**
	 * 客户档案编辑保存
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttachment/update")
	public String customerAttachmentUpdate(KHFJXX fjxx, HttpServletRequest request, HttpServletResponse response, Model model) {
		EFRowSet                                  rowset = null;
		JResponseObject                               RO = null;
		String                                  fileName;
		String                               dirFileName = null;
		String                             fileSeparator = System.getProperty("file.separator");
		MultipartHttpServletRequest     multipartRequest = (MultipartHttpServletRequest) request;
		String                               servletPath = request.getRealPath("") + fileSeparator + "upload" + fileSeparator + "cms";
		String                                 strFolder = fjxx.getF_KHBH();
		String                                forwardUrl = request.getParameter("forwardUrl");
		Map<String, MultipartFile>               fileMap = multipartRequest.getFileMap();

		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			// 上传文件名
			System.out.println("key: " + entity.getKey());
			MultipartFile mf = entity.getValue();

			try {
				rowset = EMPRowSetUtil.createRowSet(fjxx);
				PrintWriter out = response.getWriter();
				// 如果文件字节长度为零，则说明修改文字，没有改变附件文件，只是更新文字说明
				if (mf.getBytes().length == 0) {
					RO = DMTService.updateRow("KHFJXX", rowset);
				} else {
					fileName = mf.getOriginalFilename();
					dirFileName = servletPath + fileSeparator + strFolder + fileSeparator + fjxx.getF_FJBH();
					// 判断目录是否存在，每天上传的申请单都放到对应的一个目录下
					FileUtil.createDirectory(servletPath + fileSeparator + strFolder);
					File uploadFile = new File(dirFileName);
					// 先将源文件删除
					uploadFile.delete();
					// 再上传新的文件
					FileCopyUtils.copy(mf.getBytes(), uploadFile);
					rowset.putString("F_FJMC", fileName);
					RO = DMTService.updateRow("KHFJXX", rowset);
					response.getWriter().write(dirFileName);
					response.setContentType("text/html");
					response.setCharacterEncoding("utf-8");
				}
				forwardUrl += "?F_KHBH=" + fjxx.getF_KHBH();
				if (RO.getErrorCode() == -1) {
					out.write("<script>parent.callbackEditKHDAFJSubmit('false','" + RO.getErrorString() + "','')</script>");
				} else {
					out.write("<script>parent.callbackEditKHDAFJSubmit('true','" + RO.ResponseObject.toString() + "','" + forwardUrl + "')</script>");
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	/**
	 * 客户档案删除
	 * @param model
	 * @return
	 */
	@RequestMapping("/customerAttachment/delete/{F_ZDBH}")
	public ModelAndView customerAttachmentDelete(@PathVariable("F_ZDBH") String F_ZDBH) {	
		JResponseObject RO = DMTService.deleteRow("KHFJXX", F_ZDBH);
		if(RO.getErrorCode() == -1) {
			return ajaxDoneError(RO.getErrorString());
		} else {
			return ajaxDoneSuccess(RO.ResponseObject.toString());
		}
	}
	
	//--------------------------------------------------------------------------------------------------
	//描述:下载文件
	//设计: ES
	//实现: ES
	//修改:
	//--------------------------------------------------------------------------------------------------
    @RequestMapping("/download")
    public void batchDownload(@RequestParam String F_KHBH, @RequestParam String F_FJBH, HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
		String                               dirFileName = null;
		String                             fileSeparator = System.getProperty("file.separator");
		String                               servletPath = request.getRealPath("") + fileSeparator + "upload" + fileSeparator + "cms";
		String                                 strFolder = F_KHBH;
		EFRowSet                                  rowset = DMTService.getRow("KHFJXX", "F_FJBH", F_FJBH);
		try {
			dirFileName = servletPath + fileSeparator + strFolder + fileSeparator + rowset.getString("F_FJBH", "");
			File uploadFile = new File(dirFileName);
			 UploadFileUtil upFile = new UploadFileUtil();
			 upFile.download(uploadFile,rowset.getString("F_FJMC", ""), "", response);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {

		}
    }
}
